#include "Plan.h"


Plan::Plan(Mode d , float s)
{
	SetDesen(d);
	SetTranslat(0.0,0.0,0.0);
	SetRotatie(0.0,0.0,0.0);
	SetLevelOfDetail(0.5);
	culoare[3] = 1;
	size = s;
}
void Plan::SetPozitie(float x, float y, float z)
{
	pozitie[0] = x;
	pozitie[1] = y;
	pozitie[2] = z;
};

void Plan::SetTranslat(float x, float y, float z)
{
	translat[0] = x;
	translat[1] = y;
	translat[2] = z;
};
void Plan::SetScalare(float x, float y, float z)
{
	scalare[0] = x;
	scalare[1] = y;
	scalare[2] = z;
};

void Plan::SetRotatie(float x, float y, float z)
{
	rotatie[0] = x;
	rotatie[1] = y;
	rotatie[2] = z;
};

void Plan::SetCuloare(float r, float g, float b)
{
	culoare[0] = r;
	culoare[1] = g;
	culoare[2] = b;
};

void Plan::SetDesen(Mode d)
{
	desen = d;
};

float* Plan::GetPozitie()
{
	return &pozitie[0];
};

float* Plan::GetTranslat()
{
	return &translat[0];
};

float* Plan::GetScalare()
{
	return &scalare[0];
};

float* Plan::GetRotatie()
{
	return &rotatie[0];
};

float* Plan::GetCuloare()
{
	return &culoare[0];
};


Mode Plan::GetDesen()
{
	return desen;
};

void Plan::SetLevelOfDetail(float l)
{
	level = l;
};

void Plan::SetAlpha(float alpha)
{
	culoare[3] = alpha;
};
void Plan::draw()
{
	glPushMatrix();
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glEnable(GL_DEPTH_TEST);
	float a[4];
	a[0] = a[1] = a[2] = 0.0f;
	a[3] = 1.0f;
	float cul[4];
	for (int i = 0 ; i < 3 ; i++)
		cul[i] = culoare[i]*5;
	cul[3] = 1.0f;
	glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,cul);
	glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,a);
	glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,a);

	float leftMargin,rightMargin;

	leftMargin = -size;
	rightMargin = size;

	float i,j;
	float factor = 0.1f;

	// mutare in coordonate
	glTranslatef(translat[0], translat[1],translat[2]);

	// rotatie
	glRotatef( rotatie[0] , 1.0 , 0.0 , 0.0 );
	glRotatef( rotatie[1] , 0.0 , 1.0 , 0.0 );
	glRotatef( rotatie[2] , 0.0 , 0.0 , 1.0 );

	// colorare corespunzatoare
	glColor3f(culoare[0], culoare[1], culoare[2]);

	for( i = leftMargin ; i+(level*factor)<=rightMargin; i+=(level*factor))
		for(j=leftMargin;j+(level*factor)<=rightMargin; j+=(level*factor))
		{
			if( desen != WirePlan)
				glBegin(GL_QUADS);
			else
				glBegin(GL_LINE_LOOP);

			glNormal3f(0.0,1.0,0.0);
			glVertex3f(i ,  0, j);
			glVertex3f(i, 0, j+(level*factor));
			glVertex3f(i+(level*factor), 0, j+(level*factor));
			glVertex3f(i+(level*factor),  0, j);

			glEnd();
		}

		glPopMatrix();
}

Plan::~Plan(void)
{
}
